﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace HippoScript
{
    /// <summary>
    /// 字符串格式为 Map映射
    /// 
    /// 例如：
    ///  Sharp _:_                      
    ///  123+445          
    ///  _End_
    /// 格式为:     key:Sharp   value:123+445
    /// </summary>
   
    public class StringMapParser
    {
        public static Dictionary<string, string> Parser(string src)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            src = src.Trim();
            string[] arrSrc = Regex.Split(src, "_End_", RegexOptions.IgnoreCase);
            foreach (string str in arrSrc)
            {
                Regex regex;
                Match match;
                regex = new Regex(
                        @"
                     \s*(?<key> \w+)\s*_:_(?<value> [\s\S]*)
                    ", RegexOptions.IgnorePatternWhitespace
                    );
                List<string> imports = new List<string>();
                match = regex.Match(str);
                string key = match.Groups["key"].Value;
                string value = match.Groups["value"].Value;
                dic.Add(key, value);
            }
            return dic;
        }
    }
}
